﻿namespace BHS.TFSChangsetAnalyser.Model
{
    public class TfsServerConnectionDetails
    {
        public string TfsServerUrl { get; set; }

        public string TfsProjectPath { get; set; }

        public bool UseDefaultCredentials { get; set; }

        public string DomainName { get; set; }

        public string Username { get; set; }

        public string Password { get; set; }

        public bool HasServerNameAndProjectPath
        {
            get { return !string.IsNullOrEmpty(TfsServerUrl) && !string.IsNullOrEmpty(TfsProjectPath); }
        }

        public bool HasUserCredentials
        {
            get
            {
                return UseDefaultCredentials ||
                    (!string.IsNullOrEmpty(DomainName) && !string.IsNullOrEmpty(Username) && !string.IsNullOrEmpty(Password));
            }
        }

        public void ApplyDefaults(IDefaultValuesProvider defaultValuesProvider)
        {
            TfsServerUrl = defaultValuesProvider.TfsServerPath;
            TfsProjectPath = defaultValuesProvider.TfsProjectPath;
            UseDefaultCredentials = defaultValuesProvider.UseDefaultCredentials;
            DomainName = defaultValuesProvider.Domain;
            Username = defaultValuesProvider.Username;
        }
    }
}
